<template>
  <div class="hotRecruitment">
    <div class="hotRecruitmentTitle">
      <div class="title">热招岗位</div>
      <div class="more" v-if="showMoreButton">
        <span @click="handleMoreClick">更多岗位 ></span>
      </div>
    </div>
    <div class="hot-list" v-loading="loading">
      <div
        class="hotRecruitmentItem"
        v-for="(item, index) in hotRecruitmentList"
        :key="index"
        @click="toJobDetail(item)"
      >
        <div class="hotRecruitmentItemTitle">
          <el-tooltip
            effect="light"
            :content="item.jtzw"
            placement="left"
            popper-class="careerToolsItemPopper"
          >
            <span class="recuitName">{{ item.jtzw }}</span>
          </el-tooltip>
          <span class="salary">{{ item.xzdy_new }}</span>
        </div>
        <el-tooltip
          effect="light"
          :content="item.cname_all"
          placement="left"
          popper-class="careerToolsItemPopper"
        >
          <div class="hotRecruitmentItemDesc">
            <img
              :src="item.logo"
              alt=""
              srcset=""
              v-if="item.logo"
              class="hotRecruitmentItemLogo"
            />
            <span class="cname">{{ item.cname_all }}</span>
            <span class="regionname">{{ item.regionname }}</span>
          </div>
        </el-tooltip>
      </div>
      <el-empty
        description="暂无数据"
        v-if="!hotRecruitmentList.length && !loading"
      ></el-empty>
      <div
        v-if="showMoreButton"
        class="checkMoreButton"
        @click="handleMoreClick"
      >
        查看全部岗位
      </div>
    </div>
  </div>
</template>

<script>
import { hotRecruitmentHomePositionList } from '@/api/home';
export default {
  name: 'hotRecruitment',
  props: {
    showMoreButton: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      hotRecruitmentList: [],
      loading: false
    };
  },
  mounted() {
    setTimeout(() => {
      this.reqCampusJobSearch();
    }, 1500);
  },
  methods: {
    handleMoreClick() {
      //获取当前url路径，删除query参数并替换为position路由，然后用新窗口打开
      const href = window.location.href.replace(
        /\/position-detail\?.*$/,
        '/position?'
      );
      sessionStorage.setItem('switchToCampus', 1);
      window.open(href, '_blank');
    },
    reqCampusJobSearch() {
      const params = {
        // matchZpName: '', //搜索关键字
        // salary: '',
        // gznum: '',
        // eduId: '',
        pageNo: 1,
        pageSize: 10,
        keytypes: '3',
        rctypes: '0'
      };
      // let campusJobTrads = localStorage.getItem('campusJobTrads');
      // if (campusJobTrads) {
      //   campusJobTrads = JSON.parse(campusJobTrads);
      //   if (campusJobTrads[0]) {
      //     params.zpTrade = campusJobTrads[0].tradeid;
      //   }
      // }
      if (this.$store.state.user.regionId) {
        params.regionId = this.$store.state.user.regionId;
      }
      console.log('---------reqCampusJobSearch--------->', params);
      this.loading = true;
      hotRecruitmentHomePositionList(params)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((item, index) => {
              if (item.logo) {
                item.logo = item.logo.replace(/http:\/\//g, '//');
              }
            });
            this.hotRecruitmentList = res.data;
          }
        })
        .catch((e) => {
          console.log(e);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    toJobDetail(item) {
      let routeData = this.$router.resolve({
        path: `/job-detail?companyId=${item.uid}&zp_id=${item.id}`
      });
      window.open(routeData.href, '_blank');
    }
  }
};
</script>

<style lang="scss" scoped>
.hotRecruitment {
  display: flex;
  flex-direction: column;
  .hotRecruitmentTitle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #100f0f;
    font-size: 16px;
    font-weight: 800;
    line-height: 22px;
    height: 20px;
    margin-bottom: 24px;
    .more {
      height: 20px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #999999;
      line-height: 20px;
      text-align: left;
      font-style: normal;
      text-transform: none;
      cursor: pointer;
      &:hover {
        color: #076afe;
        text-decoration: underline;
      }
    }
  }
  .hot-list {
    .hotRecruitmentItem {
      margin-bottom: 24px;
      &:nth-last-child(2) {
        margin-bottom: 0;
      }
      cursor: pointer;
      .hotRecruitmentItemTitle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #222222;
        line-height: 18px;
        text-align: left;
        font-style: normal;
        margin-bottom: 9px;
        .recuitName {
          max-width: 88px;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .salary {
          height: 18px;
          font-family: PingFang-SC, PingFang-SC;
          font-weight: bold;
          font-size: 14px;
          color: #d5413d;
          line-height: 18px;
          text-align: left;
          font-style: normal;
        }
      }
      .hotRecruitmentItemDesc {
        display: flex;
        align-items: center;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 12px;
        color: #a2a5b3;
        line-height: 18px;
        text-align: left;
        font-style: normal;
        .hotRecruitmentItemLogo {
          width: 18px;
          height: 18px;
          margin-right: 8px;
        }
        .cname {
          flex: 1;
          // max-width: 70px;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .regionname {
          margin-left: 18px;
          text-align: right;
        }
      }
    }
  }
  .checkMoreButton {
    text-align: center;
    background: rgba(72, 128, 255, 0.05);
    border-radius: 8px;
    border: 1px solid #4880ff;
    padding: 10px 32px;
    font-family: PingFang-SC, PingFang-SC;
    font-weight: bold;
    font-size: 15px;
    color: #4880ff;
    cursor: pointer;
    margin-top: 24px;
  }
}
</style>
